package com.larvae.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.larvae.action.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class ActionInterceptor implements Interceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void destroy() {
		// TODO Auto-generated method stub

	}

	public void init() {
		// TODO Auto-generated method stub

	}

	public String intercept(ActionInvocation ai) throws Exception {
		// TODO Auto-generated method stub
		ActionContext context = ActionContext.getContext();
		BaseAction action = (BaseAction)ai.getAction();
		action.setContext(context);
		action.setRequest((HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST));
		action.setResponse((HttpServletResponse)context.get(ServletActionContext.HTTP_RESPONSE));
		
		return ai.invoke();
	}

}
